package com.jy.rhin.infra.cda.service;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jy.rhin.infra.cda.jiankangda.*;
import com.jy.rhin.infra.cda.mapper.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author shenguangyang
 */
@Slf4j
@Service
@RequiredArgsConstructor
@DS("health")
public class JianKangTJService {
    private final JkTiJianJBXXMapper jkTiJianJBXXMapper;
    private final JkTiJianFZJCMapper jkTiJianFZJCMapper;
    private final JkTiJianJTBCSMapper jkTiJianJTBCSMapper;
    private final JkTiJianXCZYJKWTMapper jkTiJianXCZYJKWTMapper;
    private final JkTiJianYYJLMapper jkTiJianYYJLMapper;
    private final JkZhuYuanSMapper jkZhuYuanSMapper;
    private final JkLaoNianRZYJKGLMapper jkLaoNianRZYJKGLMapper;
    private final JkGeRenJZSMapper jkGeRenJZSMapper;
    private final JkTiJianYFJZSMapper jkTiJianYFJZSMapper;

    public JianKangTJVo getJianKangTJ(String yeWuJGDM, String tiJianBH) {
        JianKangTJVo resp = new JianKangTJVo();
        LambdaQueryWrapper<JkTiJianJBXXVo> jkTiJianJBXXLqw = JkTiJianJBXXVo.lqw().eq(JkTiJianJBXXVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkTiJianJBXXVo::getTIJIANBH, tiJianBH);
        LambdaQueryWrapper<JkTiJianFZJCVo> jkTiJianFZJCLqw = JkTiJianFZJCVo.lqw().eq(JkTiJianFZJCVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkTiJianFZJCVo::getTIJIANBH, tiJianBH);
        LambdaQueryWrapper<JkTiJianJTBCSVo> jkTiJianJTBCSLqw = JkTiJianJTBCSVo.lqw().eq(JkTiJianJTBCSVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkTiJianJTBCSVo::getTIJIANJLID, tiJianBH);
        LambdaQueryWrapper<JkTiJianXCZYJKWTVo> jkTiJianXCZYJKWTLqw = JkTiJianXCZYJKWTVo.lqw().eq(JkTiJianXCZYJKWTVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkTiJianXCZYJKWTVo::getTIJIANBH, tiJianBH);
        LambdaQueryWrapper<JkTiJianYYJLVo> jkTiJianYYJLLqw = JkTiJianYYJLVo.lqw().eq(JkTiJianYYJLVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkTiJianYYJLVo::getTIJIANJLID, tiJianBH);
        LambdaQueryWrapper<JkZhuYuanSVo> jkZhuYuanSLqw = JkZhuYuanSVo.lqw().eq(JkZhuYuanSVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkZhuYuanSVo::getTIJIANJLID, tiJianBH);

        JkTiJianJBXXVo jkTiJianJBXX = jkTiJianJBXXMapper.selectOne(jkTiJianJBXXLqw);
        if (Objects.isNull(jkTiJianJBXX)) {
            return null;
        }
        resp.setJkTiJianJBXX(jkTiJianJBXX);

        LambdaQueryWrapper<JkLaoNianRZYJKGLVo> jkLaoNianRZYJKGLLqw = JkLaoNianRZYJKGLVo.lqw().eq(JkLaoNianRZYJKGLVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkLaoNianRZYJKGLVo::getPatientId, jkTiJianJBXX.getPatientId());

        LambdaQueryWrapper<JkTiJianYFJZSVo> jkTiJianYFJZSLqw = JkTiJianYFJZSVo.lqw().eq(JkTiJianYFJZSVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkTiJianYFJZSVo::getTIJIANJLID, jkTiJianJBXX.getTIJIANBH());

        LambdaQueryWrapper<JkGeRenJZSVo> jkGeRenJZSLqw = JkGeRenJZSVo.lqw().eq(JkGeRenJZSVo::getYEWUJGDM, yeWuJGDM)
                .eq(JkGeRenJZSVo::getGERENDABS, jkTiJianJBXX.getGERENDABS());

        resp.setJkTiJianFZJCList(jkTiJianFZJCMapper.selectList(jkTiJianFZJCLqw));
        resp.setJkTiJianJTBCSList(jkTiJianJTBCSMapper.selectList(jkTiJianJTBCSLqw));
        resp.setJkTiJianXCZYJKWTList(jkTiJianXCZYJKWTMapper.selectList(jkTiJianXCZYJKWTLqw));
        resp.setJkTiJianYYJLList(jkTiJianYYJLMapper.selectList(jkTiJianYYJLLqw));
        resp.setJkZhuYuanSList(jkZhuYuanSMapper.selectList(jkZhuYuanSLqw));
        resp.setJkLaoNianRZYJKGLList(jkLaoNianRZYJKGLMapper.selectList(jkLaoNianRZYJKGLLqw));
        resp.setJkGeRenJZSList(jkGeRenJZSMapper.selectList(jkGeRenJZSLqw));
        resp.setJkTiJianYFJZSList(jkTiJianYFJZSMapper.selectList(jkTiJianYFJZSLqw));
        return resp;
    }
}
